package net.skyedu.service.myattend;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.Appeal;
import net.skyedu.bean.Attendance;
import net.skyedu.dao.UserInfoDao;
//import net.skyedu.utils.SmsUtil;

public class Appeals extends HttpServlet
{
	private static final long serialVersionUID = 0x5e6111606442075L;
    public Appeals()
    {
    }

    public void destroy()
    {
        super.destroy();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        String appName = request.getParameter("appName");
        int zhao = Integer.parseInt(request.getParameter("zhao"));
        String area = request.getParameter("area").trim();
        int attId = Integer.parseInt(request.getParameter("attId"));
        int sta=Integer.parseInt(request.getParameter("status"));
        String currentPage=request.getParameter("currentPage");
        
        UserInfoDao ud = new UserInfoDao();
        Attendance att = new Attendance();
        att.setAttid(attId);
        att.setAttconfirm(2);
        ud.updateConfirm(att);
        Appeal app = new Appeal();
        app.setSendname(appName);
        app.setAppattid(attId);
        app.setContent(area);
        app.setRecipientid(zhao);
        int num = ud.addAppeal(app);
       if(num > 0){
//        	SmsUtil.sendMsg(appName+"向你申诉了","15986656534");
            out.print("<script type='text/javascript'>alert('申诉中,请等待答复!');location.replace('MonthUser?sta="+sta+"&currentPage="+currentPage+"');</script>");
        }else{
            out.print("<script type='text/javascript'>alert('ERROR:Appeal failure!');history.go(-1);</script>");
       }
    }

    public void init()
        throws ServletException
    {}
    
}
